package cherry.orange.entities;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;

import cherry.orange.Game;

public class MyPlayerEntity extends PlayerEntity {
	
	private static final float DEFAULT_SPEED = 0.15f;
	private float speed = DEFAULT_SPEED;

	public float getSpeed() {
		return speed;
	}

	public void setSpeed(float speed) {
		this.speed = speed;
	}
	
	@Override
	public void update(GameContainer container, Game game, int delta) {
		Input input = container.getInput();
		
		float dx = 0, dy = 0;
		if (input.isKeyDown(Input.KEY_LEFT)) {
			dx -= getSpeed()*delta;
		}
		if (input.isKeyDown(Input.KEY_RIGHT)) {
			dx += getSpeed()*delta;
		}
		if (input.isKeyDown(Input.KEY_UP)) {
			dy -= getSpeed()*delta;
		}
		if (input.isKeyDown(Input.KEY_DOWN)) {
			dy += getSpeed()*delta;
		}
		
		if (game.checkCollision(this, dx, 0) != null) {
			dx = 0;
		}
		if (game.checkCollision(this, 0, dy) != null) {
			dy = 0;
		}
		
		move(dx, dy);
		
		super.update(container, game, delta);
	}

}
